let MIXIN = {
	data() {
		return {
			sharetitle: '多米街',
			path: '',
			imageUrl: '',
			query: ''
		}
	},
	onLoad(options) {
		let mid = '';
		if (options.mid) {
			mid = options.mid;
		}
		if (options.scene) {
			let scene = decodeURIComponent(options.scene);
			mid = this.gup('mid', scene);
		}
		if(mid!=''){
			uni.setStorageSync('mid', mid);
		}
		
		let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
		// 需要获取转发URL的页面路由
		let pathArr = [
			{
				type: 'home',
				child:['/mallHome/index','/index/index']
			},
			{
				type: 'goods',
				child:['/product/product','/product/groupbuy']
			},
			{
				type: 'goodsList',
				child:['/product/list']
			},
			{
				type: 'merch',
				child:['/shoplist/shopgoods']
			},
			{
				type: 'goodsvod',
				child:['/product/videoDetail']
			},
			{
				type: 'other',
				child:['/mallHome/selfMall','/category/category','/goodlist/goodlist','/business/accounts','/user/vipShop','/shoptab/shoplist','/user/vip']
			},
		];
		// 禁止转发的路由页面 需要完整的页面路径，包含动态参数的路径不适用
		let banPath = [
			'/pages/agent/QRcode'
		];
		if (routes.length > 0 && routes[routes.length - 1].$page) {
			this.path = routes[routes.length - 1].$page.fullPath; //获取当前页面路由
			console.log(this.path);
			// 禁用页面转发
			if(banPath.includes(this.path)){
				uni.hideShareMenu();
			}
			let type;
			let cid = routes[routes.length - 1].options.id ? routes[routes.length - 1].options.id : 0;
			pathArr.forEach((item)=>{
				item.child.forEach((items)=>{
					if(this.path.includes(items)){
						type = item.type;
						this.$axios('WxInfo/getConfig', 'POST', 'shop', {
							url: this.path,
							type,
							cid
						}).then(res => {
							if (res.data.code == 200) {
								if(res.data.data.shareinfo.title){
									this.sharetitle = res.data.data.shareinfo.title;
								}
								this.path = res.data.data.shareinfo.url;
								this.query = res.data.data.shareinfo.url.split('?')[1];
								this.imageUrl = res.data.data.shareinfo.imgurl;
							}
						})
					}
				})
			})
			
			
			// return;
	// 		if (this.path.indexOf('/product/list') != -1 || this.path.indexOf('/mallHome/index') != -1 || this.path.indexOf('/product/product') != -1 || this.path.indexOf('/shoplist/shopgoods') != -1 || this.path.indexOf('/index/index') != -1 || this.path.indexOf('/product/groupbuy') != -1 || this.path.indexOf('/product/videoDetail') != -1 || this.path.indexOf('/mallHome/selfMall') != -1 || this.path.indexOf('/category/category') != -1 || this.path.indexOf('/goodlist/goodlist') != -1 || this.path.indexOf('/business/accounts') != -1 || this.path.indexOf('/user/vipShop') != -1 || this.path.indexOf('/shoptab/shoplist') != -1){
	// 			let type = this.path.indexOf('/product/list') != -1 ? 'goodsList' : this.path.indexOf('/product/product') != -1 ? 'goods' : this.path.indexOf('/index/index') != -1 ? 'home' :'merch';
	// 			if(this.path.indexOf('/product/groupbuy') != -1){
	// 				type='goods';
	// 			}
	// 			if(this.path.indexOf('/mallHome/index') != -1){
	// 				type='home';
	// 			}
	// 			if(this.path.indexOf('/product/videoDetail') != -1){
	// 				type='goodsvod';
	// 			}
	// 			if(this.path.indexOf('/mallHome/selfMall') != -1 || this.path.indexOf('/category/category') != -1 || this.path.indexOf('/goodlist/goodlist') != -1 || this.path.indexOf('/business/accounts') != -1 || this.path.indexOf('/user/vipShop') != -1 || this.path.indexOf('/shoptab/shoplist') != -1){
	// 				type = 'other'
	// 			}
	// let cid = routes[routes.length - 1].options.id ? routes[routes.length - 1].options.id : 0;
	// let obj = {
	// 	url: this.path,
	// 	type,
	// 	cid
	// };
				// this.$axios('WxInfo/getConfig', 'POST', 'shop', obj).then(res => {
				// 	if (res.data.code == 200) {
				// 		if(res.data.data.shareinfo.title){
				// 			this.title = res.data.data.shareinfo.title;
				// 		}
				// 		this.path = res.data.data.shareinfo.url;
				// 		this.query = res.data.data.shareinfo.url.split('?')[1];
				// 		this.imageUrl = res.data.data.shareinfo.imgurl;
				// 		// if(type=='goodsvod') this.imageUrl = res.data.data.shareinfo.imgurl;
				// 		console.log(this.query)
				// 	}
				// })
	// 		}
		}
	},
	methods: {
		gup(name, url) {
			if (url) url = url ? '?' + url : location.href;
			name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
			var regexS = "[\\?&]" + name + "=([^&#]*)";
			var regex = new RegExp(regexS);
			var results = regex.exec(url);
			return results == null ? null : results[1];
		}
	},
	//转发分享
	 onShareAppMessage() {
	 	return {
	 		title: this.sharetitle,
	 		path: this.path,
			imageUrl: this.imageUrl
	 	}
	 },
	 onShareTimeline() {
	 	return {
	 		title: this.sharetitle,
	 		// path: this.path,
			query: this.query,
			imageUrl: this.imageUrl
	 	}
	 },
};
export default MIXIN;